home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5079 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  62 lines

  1. Path: usenet.ggu.edu!user
  2. From: elaw@usenet.ggu.edu (Elaine Law)
  3. Newsgroups: comp.lang.c
  4. Subject: Re(2): Finding a prime number
  5. Date: Sun, 11 Feb 96 23:20:51 -0800
  6. Organization: ggu.edu
  7. Message-ID: <1844965.ensmtp@usenet.ggu.edu>
  8. NNTP-Posting-Host: usenet.ggu.edu
  9. X-Newsreader: ExpressNet/SMTP v1.1.5
  10.  
  11. Give this a try.
  12.  
  13. #include<stdio.h>
  14. #include<conio.h>
  15. void main(void)
  16. {
  17.  long inp=0, ctr=0;
  18.  int total=0, ctr2=0;
  19.  clrscr();
  20.  do { printf("Enter a number from 1 to 1000000: ");
  21.       scanf("%d", &inp);
  22.     } while (inp<1 || inp>1000000);
  23.  printf("\nThe prime numbers are:\n ");
  24.  for (ctr=1; ctr<=inp; ctr++)
  25.    { for (total=0, ctr2=1; ctr2<ctr; ctr2++)
  26.        { if (ctr%ctr2==0) 
  27.        { total++; }
  28.        }
  29.      if (total<2)
  30.        { printf("%d\t", ctr); }
  31.    }
  32. }
  33. ===========
  34. and lo, there was much rejoicing among the people, as
  35.   kannan@emirates.net.ae (Kannan) writes:
  36.  
  37. >Is it not easy to just check whether the integer is divisible by 2 or
  38. >3 and decide (except 1 & 3 which is a prime number)? For ex., 723232
  39. >this would be divisible by 2 so not a prime number. And 997 cannot be
  40. >divided by these 2. This is prime number. Please correct me if I am
  41. >wrong without attacking me personally :)
  42.  
  43. 35/2 = 17.5_
  44. 35/3 = 11.66
  45.  
  46. therefore, 35 is prime.
  47.  
  48. .hymie                                                
  49. hymie@lactose.smart.net
  50. self-appointed chairman of the 3-man keep-the-browns-in-cleveland foundation
  51. GCS/M d-(--) s: a25 C++ UL++ P+ E- W++ N+++ w--- M- PS+ PGP+ Y+ t+/* tv+ DI++
  52. b+ G+ h- e++/* r++ y+    pgp key at web page   
  53. http://www.smart.net/~hymowitz/
  54. ===============================================================================
  55.  
  56. sorry, this .sig is not a winner.  remember to check the .sig every time
  57. you read a hymie! brand post or letter.  please try again.  good luck!
  58. ===============================================================================
  59.  
  60.  
  61.  
  62.